<?php

namespace app\api\controller\shop;

use app\admin\model\Deviceorder;
use app\common\controller\Api;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {

        $user = $this->auth->getUser();
        $deviceOrderModel = new Deviceorder();
        $todayAmount = $deviceOrderModel->where('status','not in',['paying','refund'])->whereTime('create_time','today')->where('agent_id',$user['id'])->sum('price');
        $todayCount = $deviceOrderModel->where('status','not in',['paying','refund'])->whereTime('create_time','today')->where('agent_id',$user['id'])->count('id');
        $todayRefund = $deviceOrderModel->where('status','refund')->whereTime('create_time','today')->where('agent_id',$user['id'])->sum('price');

        $yesAmount = $deviceOrderModel->where('status','not in',['paying','refund'])->whereTime('create_time','yesterday')->where('agent_id',$user['id'])->sum('price');
        $yesCount = $deviceOrderModel->where('status','not in',['paying','refund'])->whereTime('create_time','yesterday')->where('agent_id',$user['id'])->count('id');
        $yesRefund = $deviceOrderModel->where('status','refund')->whereTime('create_time','yesterday')->where('agent_id',$user['id'])->sum('price');


        $ret  = array();
        $ret['todayAmount'] = $todayAmount;
        $ret['todayCount'] = $todayCount;
        $ret['todayRefund'] = $todayRefund;

        $ret['yesAmount'] = $yesAmount;
        $ret['yesCount'] = $yesCount;
        $ret['yesRefund'] = $yesRefund;

        $this->success('',$ret);
    }
}
